home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / emulator / code.lua next >
Text File  |  2005-07-16  |  9KB  |  256 lines

  1.  
  2. -- -----------------------------------------------------------------
  3. -- Init
  4. -- -----------------------------------------------------------------
  5. local function prog_init()
  6.     initModels()
  7.     local pokus = getRestartCount()
  8.     local roompole = createArray(3)
  9.  
  10.  
  11.     -- -------------------------------------------------------------
  12.     local function prog_init_room()
  13.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  14.  
  15.         room:setEffect("zx")
  16.         room.pocitadlo = 0
  17.         room.uvod = 0
  18.         room.nekdy = 100 + random(5000)
  19.         room.pixely = 0
  20.         room.hra = 0
  21.         room.lore = 0
  22.         room.premyslis = 0
  23.         room.load = 0
  24.         room.opakovani = 0
  25.         room.tlaci = 0
  26.         room.skladat = 0
  27.         room.miner = 0
  28.  
  29.         return function()
  30.             if no_dialog() and isReady(small) and isReady(big) then
  31.                 if room.nekdy > 0 then
  32.                     room.nekdy = room.nekdy - 1
  33.                 end
  34.                 room.pocitadlo = room.pocitadlo + 1
  35.                 if room.uvod == 0 then
  36.                     room.uvod = 1
  37.                     switch(pokus){
  38.                         [1] = function()
  39.                             pom1 = 1
  40.                         end,
  41.                         [2] = function()
  42.                             pom1 = 2
  43.                         end,
  44.                         default = function()
  45.                             pom1 = random(2) + 1
  46.                         end,
  47.                     }
  48.                     if pom1 == 1 then
  49.                         addm(random(42) + 9, "zx-m-pametnici")
  50.                         if pokus < 5 + random(5) or random(100) < 50 then
  51.                             addv(15, "zx-v-osmibit")
  52.                         end
  53.                     else
  54.                         addv(random(42) + 9, "zx-v-roboti")
  55.                         addm(9, "zx-m-highway")
  56.                     end
  57.                 elseif room.pixely == 0 and room.nekdy == 0 then
  58.                     room.pixely = 1
  59.                     addm(9, "zx-m-pixel")
  60.                     if random(100) < 40 and room.hra == 0 then
  61.                         room.hra = 1
  62.                         addv(5, "zx-v-hry")
  63.                     end
  64.                 elseif room.hra == 0 and big.dir ~= dir_no and jet.dir ~= dir_no then
  65.                     room.hra = 1
  66.                     addv(20 + random(50), "zx-v-hry")
  67.                 elseif room.premyslis == 0 and big.nehybe_se > 90 and room.pocitadlo > 500 + random(200) then
  68.                     room.premyslis = 1
  69.                     addm(0, "zx-m-premyslis")
  70.                     if room.hra == 0 and random(100) < 25 then
  71.                         addv(4, "zx-v-hry")
  72.                         room.hra = 1
  73.                     else
  74.                         pom1 = random(6)
  75.                         if pom1 < 5 then
  76.                             addv(12, "zx-v-pamet")
  77.                         end
  78.                         if pom1 > 1 then
  79.                             addv(5 + random(4), "zx-v-otazka")
  80.                         end
  81.                         if random(5) > 0 then
  82.                             addm(10 + random(4), "zx-m-necodosebe")
  83.                         end
  84.                     end
  85.                 elseif room.lore == 0 and dist(knightik, small) < 5 and isIn(small.Y, {2, 3, 4}) and not small:isLeft() and random(100) < 20 then
  86.                     room.lore = 1
  87.                     addm(9 * random(2), "zx-m-knight")
  88.                 elseif room.load < 4 and room.pocitadlo > 400 + 200 * room.load + random(200) then
  89.                     room.load = room.load + 1
  90.                     if room.load == 1 then
  91.                         addv(0, "zx-v-nahravani")
  92.                     elseif random(2) == 0 then
  93.                         addv(0, "zx-v-nahravani")
  94.                     end
  95.                 elseif room.tlaci == 0 and small.dir ~= dir_no and small:getState() == "pushing" and small.tlacit_jeste == 0 then
  96.                     room.tlaci = 1
  97.                     addm(5, "zx-m-ocel")
  98.                 elseif room.skladat == 0 and roompole[2] < 2 and (jet1.dir ~= dir_no or jet2.dir ~= dir_no or jet3.dir ~= dir_no) and small.dir ~= dir_no and random(8) == 0 then
  99.                     if pokus > 2 and random(100) < 60 then
  100.                         room.skladat = 1
  101.                     else
  102.                         room.skladat = 1
  103.                         roompole[2] = roompole[2] + 1
  104.                         addm(9, "zx-m-jetpack")
  105.                     end
  106.                 elseif room.miner == 0 and big.dir == dir_no and dist(manic, big) < 6 and random(100) < 8 then
  107.                     if pokus > 3 and random(100) < 10 + 50 * roompole[1] then
  108.                         room.miner = 1
  109.                     else
  110.                         roompole[1] = 1
  111.                         room.miner = 1
  112.                         addv(5, "zx-v-manicminer")
  113.                     end
  114.                 end
  115.             else
  116.                 room.pocitadlo = 0
  117.             end
  118.         end
  119.     end
  120.  
  121.     -- -------------------------------------------------------------
  122.     local function prog_init_knightik()
  123.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  124.  
  125.         knightik.stav = 0
  126.         knightik.poc = random(200) + 100
  127.  
  128.         return function()
  129.             stav_table = {
  130.                 [0] = function()
  131.                     if knightik.poc > 0 then
  132.                         knightik.poc = knightik.poc - 1
  133.                     else
  134.                         knightik.stav = knightik.stav + 1
  135.                         knightik.poc = 42
  136.                     end
  137.                 end,
  138.                 [1] = function()
  139.                     if knightik.poc == 0 then
  140.                         if knightik.stav == 3 then
  141.                             knightik.stav = 0
  142.                         else
  143.                             knightik.stav = 2
  144.                         end
  145.                         knightik.afaze = knightik.stav * 3
  146.                         knightik.poc = 300 - knightik.stav * 50
  147.                     else
  148.                         knightik.poc = knightik.poc - 1
  149.                         if math.mod(knightik.poc, 3) == 2 then
  150.                             knightik.afaze = random(4) + 2
  151.                         end
  152.                     end
  153.                 end,
  154.                 [5] = function()
  155.                     knightik.stav = knightik.stav + 1
  156.                 end,
  157.                 [9] = function()
  158.                     knightik.stav = 0
  159.                     knightik.afaze = 0
  160.                 end,
  161.             }
  162.  
  163.             stav_table[2] = stav_table[0]
  164.  
  165.             stav_table[1] = stav_table[3]
  166.  
  167.             stav_table[6] = stav_table[5]
  168.             stav_table[7] = stav_table[5]
  169.             stav_table[8] = stav_table[5]
  170.             switch(knightik.stav)(stav_table)
  171.             if knightik.stav == 0 and random(100) == 14 then
  172.                 knightik.stav = 5
  173.                 knightik.afaze = 1
  174.             end
  175.             knightik:updateAnim()
  176.         end
  177.     end
  178.  
  179.     -- -------------------------------------------------------------
  180.     local function prog_init_trubys()
  181.         return function()
  182.             if trubys.afaze == 3 then
  183.                 trubys.afaze = 0
  184.             else
  185.                 trubys.afaze = trubys.afaze + 1
  186.             end
  187.             trubys:updateAnim()
  188.         end
  189.     end
  190.  
  191.     -- -------------------------------------------------------------
  192.     local function prog_init_big()
  193.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  194.  
  195.         big.nehybe_se = 0
  196.  
  197.         return function()
  198.             if big.dir ~= dir_no then
  199.                 big.nehybe_se = 0
  200.             else
  201.                 big.nehybe_se = big.nehybe_se + 1
  202.             end
  203.         end
  204.     end
  205.  
  206.     -- -------------------------------------------------------------
  207.     local function prog_init_small()
  208.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  209.  
  210.         small.tlacit_jeste = 20 + random(80)
  211.  
  212.         return function()
  213.             if small.dir ~= dir_no and small.tlacit_jeste > 0 and small:getState() == "pushing" then
  214.                 small.tlacit_jeste = small.tlacit_jeste - 1
  215.             end
  216.         end
  217.     end
  218.  
  219.     -- --------------------
  220.     local update_table = {}
  221.     local subinit
  222.     subinit = prog_init_room()
  223.     if subinit then
  224.         table.insert(update_table, subinit)
  225.     end
  226.     subinit = prog_init_knightik()
  227.     if subinit then
  228.         table.insert(update_table, subinit)
  229.     end
  230.     subinit = prog_init_trubys()
  231.     if subinit then
  232.         table.insert(update_table, subinit)
  233.     end
  234.     subinit = prog_init_big()
  235.     if subinit then
  236.         table.insert(update_table, subinit)
  237.     end
  238.     subinit = prog_init_small()
  239.     if subinit then
  240.         table.insert(update_table, subinit)
  241.     end
  242.     return update_table
  243. end
  244. local update_table = prog_init()
  245.  
  246.  
  247. -- -----------------------------------------------------------------
  248. -- Update
  249. -- -----------------------------------------------------------------
  250. function prog_update()
  251.     for key, subupdate in pairs(update_table) do
  252.         subupdate()
  253.     end
  254. end
  255.  
  256.